function [fitresult, gof] = createFit(W, Y4)
%CREATEFIT(W,Y4)
%  Create a fit.
%
%  Data for 'untitled fit 1' fit:
%      X Input : W
%      Y Output: Y4
%  Output:
%      fitresult : a fit object representing the fit.
%      gof : structure with goodness-of fit info.
%
%  另请参阅 FIT, CFIT, SFIT.

%  由 MATLAB 于 20-Apr-2022 10:48:09 自动生成


%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( W, Y4 );

% Set up fittype and options.
ft = fittype( '4*gd*gr/(x^2+(gr+gd)^2)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.DiffMaxChange = 1e-10;
opts.DiffMinChange = 1e-10;
opts.Display = 'Off';
opts.Lower = [1e-05 1e-05];
opts.StartPoint = [1e-05 1e-05];
opts.TolFun = 1e-10;
opts.TolX = 1e-10;
opts.Upper = [0.1 0.1];

% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );

% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'Y vs. W', ' fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'W', 'Interpreter', 'none' );
ylabel( 'Y', 'Interpreter', 'none' );
grid on
end

